<?php
namespace app\models;

use yii\db\ActiveRecord;

class Article extends ActiveRecord
{
    public function getCategory()
    {

//        //方法一:会自动调用one()方法 可以省略one()
//        $category = $this->hasOne(Category::className(),['cid'=>'article_id'])->asArray()->one();
//        return $category;

        方法二:
                $category = $this->hasOne(Category::className(),['cid'=>'article_id']);
        return $category;
    }
}
